#ifndef CVar_h__
#define CVar_h__

#include <eastl/map.h>
#include <eastl/string.h>

enum
{
	CF_RO,
	CF_RW,

	CF_SAVED
};

class CVar
{
public:
	virtual ~CVar() {}
	virtual int Flags() const = 0;
	virtual const char* Type() const = 0;
	virtual const char* Name() const = 0;
	virtual void Reset() = 0;
protected:
	void AddSelf();
};

eastl::map<eastl::string,CVar*>* CVarList = 0;

void CVar::AddSelf()
{
	if (!CVarList)
	{
		CVarList = new eastl::map<eastl::string,CVar*>;
	}
	(*CVarList)[Name()] = this;
}

#define CVAR(type,name,def,flags) \
	class name##_CVar : public CVar {\
	public: \
		name##_CVar () { AddSelf(); Reset(); } \
		virtual int Flags() const { return flags; } \
		virtual const char* Type() const { return #type; } \
		virtual const char* Name() const { return #name; } \
		type& operator()() { return Value; } \
		const type& operator () () const { return Value; } \
		virtual void Reset() { Value = def; }\
	protected: \
		type Value; \
	} name ;


#endif // CVar_h__